<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Example: Enrich your data based on exact values | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'match-enrich-policy-type.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/match-enrich-policy-type.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/match-enrich-policy-type.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/match-enrich-policy-type.html" rel="nofollow" target="_blank">../en/match-enrich-policy-type.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="ingest.html">Ingest node</a></span>
»
<span class="breadcrumb-link"><a href="ingest-enriching-data.html">Enrich your data</a></span>
»
<span class="breadcrumb-node">Example: Enrich your data based on exact values</span>
</div>
<div class="navheader">
<span class="prev">
<a href="geo-match-enrich-policy-type.html">« Example: Enrich your data based on geolocation</a>
</span>
<span class="next">
<a href="ingest-processors.html">Processors »</a>
</span>
</div>
<div class="section xpack">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="match-enrich-policy-type"></a>Example: Enrich your data based on exact values<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ingest/enrich.asciidoc">edit</a><a class="xpack_tag" href="https://www.elastic.co/subscriptions"></a>
</h2>
</div></div></div>
<p><code class="literal">match</code> <a class="xref" href="ingest-enriching-data.html#enrich-policy">enrich policies</a> match enrich data to incoming
documents based on an exact value, such as a email address or ID, using a
<a class="xref" href="query-dsl-term-query.html" title="Term query"><code class="literal">term</code> query</a>.</p>
<p>The following example creates a <code class="literal">match</code> enrich policy that adds user name and
contact information to incoming documents based on an email address. It then
adds the <code class="literal">match</code> enrich policy to a processor in an ingest pipeline.</p>
<p>Use the <a class="xref" href="indices-create-index.html" title="Create index API">create index API</a> or <a class="xref" href="docs-index_.html" title="Index API">index
API</a> to create a source index.</p>
<p>The following index API request creates a source index and indexes a
new document to that index.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /users/_doc/1?refresh=wait_for
{
    "email": "mardy.brown@asciidocsmith.com",
    "first_name": "Mardy",
    "last_name": "Brown",
    "city": "New Orleans",
    "county": "Orleans",
    "state": "LA",
    "zip": 70116,
    "web": "mardy.asciidocsmith.com"
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1075.console"></div>
<p>Use the put enrich policy API to create an enrich policy with the <code class="literal">match</code>
policy type. This policy must include:</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
One or more source indices
</li>
<li class="listitem">
A <code class="literal">match_field</code>,
the field from the source indices used to match incoming documents
</li>
<li class="listitem">
Enrich fields from the source indices you’d like to append to incoming
documents
</li>
</ul>
</div>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /_enrich/policy/users-policy
{
    "match": {
        "indices": "users",
        "match_field": "email",
        "enrich_fields": ["first_name", "last_name", "city", "zip", "state"]
    }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1076.console"></div>
<p>Use the <a class="xref" href="execute-enrich-policy-api.html" title="Execute enrich policy API">execute enrich policy API</a> to create an
enrich index for the policy.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST /_enrich/policy/users-policy/_execute</pre>
</div>
<div class="console_widget" data-snippet="snippets/1077.console"></div>
<p>Use the <a class="xref" href="put-pipeline-api.html" title="Put pipeline API">put pipeline API</a> to create an ingest pipeline. In
the pipeline, add an <a class="xref" href="enrich-processor.html" title="Enrich Processor">enrich processor</a> that includes:</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
Your enrich policy.
</li>
<li class="listitem">
The <code class="literal">field</code> of incoming documents used to match documents
from the enrich index.
</li>
<li class="listitem">
The <code class="literal">target_field</code> used to store appended enrich data for incoming documents.
This field contains the <code class="literal">match_field</code> and <code class="literal">enrich_fields</code> specified in your
enrich policy.
</li>
</ul>
</div>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /_ingest/pipeline/user_lookup
{
  "description" : "Enriching user details to messages",
  "processors" : [
    {
      "enrich" : {
        "policy_name": "users-policy",
        "field" : "email",
        "target_field": "user",
        "max_matches": "1"
      }
    }
  ]
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1078.console"></div>
<p>Use the ingest pipeline to index a document. The incoming document should
include the <code class="literal">field</code> specified in your enrich processor.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /my_index/_doc/my_id?pipeline=user_lookup
{
  "email": "mardy.brown@asciidocsmith.com"
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1079.console"></div>
<p>To verify the enrich processor matched and appended the appropriate field data,
use the <a class="xref" href="docs-get.html" title="Get API">get API</a> to view the indexed document.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET /my_index/_doc/my_id</pre>
</div>
<div class="console_widget" data-snippet="snippets/1080.console"></div>
<p>The API returns the following response:</p>
<div class="pre_wrapper lang-console-result">
<pre class="programlisting prettyprint lang-console-result">{
  "found": true,
  "_index": "my_index",
  "_type": "_doc",
  "_id": "my_id",
  "_version": 1,
  "_seq_no": 55,
  "_primary_term": 1,
  "_source": {
    "user": {
      "email": "mardy.brown@asciidocsmith.com",
      "first_name": "Mardy",
      "last_name": "Brown",
      "zip": 70116,
      "city": "New Orleans",
      "state": "LA"
    },
    "email": "mardy.brown@asciidocsmith.com"
  }
}</pre>
</div>
</div>
<div class="navfooter">
<span class="prev">
<a href="geo-match-enrich-policy-type.html">« Example: Enrich your data based on geolocation</a>
</span>
<span class="next">
<a href="ingest-processors.html">Processors »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>